package com.bt.lms.service.impl;

import com.bt.lms.entity.StuBasicInfo;
import com.bt.lms.dao.servise.StuBasicInfoDao;
import com.bt.lms.dao.servise.impl.StuBasicInfoDaoImpl;
import com.bt.lms.service.StuBasicInfoService;

import java.sql.SQLException;

/**
 * 学员基本信息实现
 */
public class StuBasicInfoServiceImpl implements StuBasicInfoService {
    @Override
    public boolean edit(Long id, StuBasicInfo stuBasicInfo) throws SQLException {
        StringBuilder basicSqlSB = new StringBuilder();
        basicSqlSB.append("update stu_basic_info set")
                .append(" code = ?,name = ? ,sex = ?,birth_date =?,native = ?,nation = ?,birthplace = ?")
                .append(",id_type = ?,id_card = ?,marital_status = ?,politics_status = ?")
                .append(" where id = ?");
        String sql = new String(basicSqlSB);


        StuBasicInfoDao stuBasicInfoDao = new StuBasicInfoDaoImpl();
        stuBasicInfoDao.updateBasicInfo(sql, stuBasicInfo,id);

        //扩展信息
        StringBuilder extendSqlSB = new StringBuilder();
        extendSqlSB.append("update stu_extend_info set")
                        .append(" english_name = ? ,name_phoneticize = ?,former_name = ?,faith = ?,nationality = ?,alien = ?,physical_condition = ?")
                        .append(",blood_type = ?,start_id_card_validity = ?,stop_id_card_validity = ?,only_child = ?")
                        .append(" where stu_basic_info_id = ?");
        String sql1 = new String(extendSqlSB);
        stuBasicInfoDao.updateExtendInfo(sql1,stuBasicInfo,id);


        return true;
    }

    @Override
    public boolean editHeadImage(Long id, String path) throws SQLException {
        String sql = "update picture_info set picture_path = ? where deleted = ? and stu_basic_info_id = ?";
        StuBasicInfoDao stuBasicInfoDao = new StuBasicInfoDaoImpl();
        stuBasicInfoDao.updatePictureInfo(sql,path,id);


        return false;
    }

    @Override
    public boolean deleteHeadImage(Long id) throws SQLException {
        String sql = "update picture_info set deleted = ? where stu_basic_info_id = ?";

        StuBasicInfoDao stuBasicInfoDao = new StuBasicInfoDaoImpl();
        stuBasicInfoDao.deletePictureInfo(sql,id);
        return false;
    }
}
